import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login.vue'
import Home from '@/views/Home.vue'
import MainPage from '@/views/MainPage.vue'
import PostList from '@/views/PostList.vue'
import PostPublish from '@/views/PostPublish.vue'

Vue.use(VueRouter)

// 隐藏重复路由跳转的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  routes: [
    {
      path: '/',
      component: Home,
      children: [ // 配置子路由
        { path: '', component: MainPage, name: 'home' },
        { path: '/post-list', component: PostList, name: 'post-list' },
        { path: '/post-publish', component: PostPublish, name: 'post-publish' }
      ]
    },
    { path: '/login', component: Login, name: 'login' }
  ]
})

export default router
